package cn.edu.zafu.bigdata.smj;

public class Cube {
    private double length;
    private double width;
    private double height;

    public Cube(double length,double width,double height){
        this.length=length;
        this.width=width;
        this.height=height;
    }

    public  double getLength(){
        return length;
    }

    public  double getWidth() {
        return width;
    }

    public double getHeight(){
        return height;
    }

    @Override
    public boolean equals(Object obj) {
        // 检查是否为同一对象
        if (this == obj) {
            return true;
        }
        // 检查是否为空或类型不同
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        // 类型转换
        Cube other = (Cube) obj;
        // 检查长、宽、高是否相等
        return Double.compare(other.length, length) == 0 &&
                Double.compare(other.width, width) == 0 &&
                Double.compare(other.height, height) == 0;
    }

    // 测试用例
    public static void main(String[] args) {
        Cube cube1 = new Cube(3.0, 4.0, 5.0);
        Cube cube2 = new Cube(3.0, 4.0, 5.0);
        Cube cube3 = new Cube(2.0, 4.0, 5.0);

        // 验证两个正方体的长、宽和高相等时equals方法返回true
        System.out.println("cube1 equals cube2: " + cube1.equals(cube2));
        // 验证两个正方体的长、宽和高不完全相等时equals方法返回false
        System.out.println("cube1 equals cube3: " + cube1.equals(cube3));
    }
}
